//
// Created by Administrator on 2021/8/8.
//

#ifndef STRUCTVIEW_CHECKVIEW_H
#define STRUCTVIEW_CHECKVIEW_H

#include "ViewInterface.h"
#include <type_traits>

namespace details {
    /*
     * sometimes type of data is not equal to view param type, cause it has implicit convertor.
     */
    template<typename ViewElem, typename DataElem>
    class CheckView : public ViewInterface {
        using RealType = typename std::remove_reference<ViewElem>::type;

    public:
        CheckView(ViewElem& sel, DataElem&& _value, const char* _name) :
                select{sel}, value{_value}, name{_name} {}

        auto build() -> void override {
        }

        auto equal() -> bool override {
            return true;
        }

    private:
        ViewElem& select;
        DataElem value;
        const char* name;
    };
}

#define __new_check_view__(elem, elem_name, value) new details::CheckView<decltype(elem), decltype(value)>(elem, value, TO_STRING(elem_name))

#define __def_check_view__(param, value)       \
[](auto&& parent) {                            \
    return __new_check_view__(parent, param, value); \
}(parent.param)

#define VCheck(param_name, value) __append_view__(__def_check_view__(param_name, value))
#define VAssign(param_name, value) VCheck(param_name, value)

#endif //STRUCTVIEW_CHECKVIEW_H
